package leecode

func twoSum(numbers []int, target int) []int {
	result := make([]int, 0, 2)
	for i := 0; i < len(numbers); i++ {
		rightNum := target - numbers[i]
		//在数组中寻找rightNum即可
		left := i
		right := len(numbers) - 1 - i
		for left <= right {
			mid := (left + right) >> 1
			if numbers[mid] < target {
				left = mid + 1
			} else if numbers[mid] > target {
				right = mid - 1
			} else {
				result = append(result, numbers[i])
				result = append(result, rightNum)
				goto End
			}
		}
	}
End:
	return result
}
